import * as bcrypt from 'bcryptjs'

export default class Crypto {
  saltRounds: number = 10

  // 加密密码
  static async hashPassword(password: string): Promise<string> {
    const salt = await bcrypt.genSalt(10) // 盐值的轮数是10，值越大越安全，但也会更慢
    // 使用盐值对密码进行哈希加密
    return await bcrypt.hash(password, salt)
  }

  // 验证密码
  static async comparePassword(plainPassword: string, hashedPassword: string): Promise<boolean> {
    return await bcrypt.compare(plainPassword, hashedPassword)
  }
}
